<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <meta charset="utf-8" />
    <title>后台管理－添加平台</title>

    <meta name="keywords" content="{$Think.CONFIG.keywords}" />
    <meta name="description" content="{$Think.CONFIG.description}" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />

    <include file="Public/head" />
    <script src="__PUBLIC__/hytn/js/jquery.js" type="text/javascript"></script>

</head>

<body class="no-skin">
<include file="Public/header" />
<div class="main-container" id="main-container">
    <script type="text/javascript">
        try{ace.settings.check('main-container' , 'fixed')}catch(e){}
    </script>
    <?php $Platform='active';$ptitle='平台管理';$title='添加';?>
    <include file="Public/sidebar" />
    <div class="main-content">
        <div class="main-content-inner">
            <!-- #section:basics/content.breadcrumbs -->
            <include file="Public/breadcrumbs" />

            <!-- /section:basics/content.breadcrumbs -->
            <div class="page-content">
                <include file="Public/set" />

                <!-- /section:settings.box -->
                <div class="row">
                    <div class="col-xs-12">
                        <!-- PAGE CONTENT BEGINS -->
                        <div class="form-horizontal">

                            <div class="space-4"></div>
                            <div class="form-group">
                                <label class="col-sm-1 control-label no-padding-right" for="title"> 网站标题 </label>
                                <div class="col-sm-9">
                                    <input type="text" name="title" id="title" class="col-xs-10 col-sm-5" value="{$list.title}">
                                </div>
                            </div>

                            <div class="space-4"></div>
                            <form id="form1" enctype="multipart/form-data" action="{:U('Upload/upload')}" method="post">
                                <div class="form-group">
                                    <label class="col-sm-1 control-label no-padding-right" for="logo"> 网站LOGO </label>
                                    <div class="col-sm-9">
                                        <div class="col-xs-10 col-sm-5"><input type="file" class="txt_file" id="logo" class="up_img" name="logo" accept="image/*">
                                            <img name='pic' id='pic' src='__ROOT__/{$list.logo}' style="width:120px;height:80px;padding-top:10px;">
                                        </div>
												<span class="help-inline col-xs-12 col-sm-7">
													<span class="middle">仅支持jpg、png，且小于1MB。</span>
												</span>
                                    </div>
                                </div>
                            </form>
                            <div class="space-4"></div>

                            <div class="form-group">
                                <label class="col-sm-1 control-label no-padding-right" for="keywords"> 关键字 </label>
                                <div class="col-sm-9">
                                    <textarea name="keywords" id="keywords" cols="45" rows="5">{$list.keywords}</textarea>
                                </div>
                            </div>

                            <div class="space-4"></div>

                            <div class="form-group">
                                <label class="col-sm-1 control-label no-padding-right" for="contents"> 网站描述 </label>
                                <div class="col-sm-9">
                                    <textarea name="contents" id="contents" cols="45" rows="5">{$list.contents}</textarea>
                                </div>
                            </div>

                            <div class="space-4"></div>

                            <div class="form-group">
                                <label class="col-sm-1 control-label no-padding-right" for="copyright"> 版权 </label>
                                <div class="col-sm-9">
                                    <input type="text" name='copyright' id='copyright' placeholder='网站版权' class='col-xs-10 col-sm-5' value='{$list.copyright}'>
                                </div>
                            </div>

                            <div class="space-4"></div>

                            <div class="form-group">
                                <label class="col-sm-1 control-label no-padding-right" for="record"> 备案号 </label>
                                <div class="col-sm-9">
                                    <input type="text" name='record' id='record' placeholder='备案号' class='col-xs-10 col-sm-5' value='{$list.record}'>
                                </div>
                            </div>

                            <div class="space-4"></div>

                            <div class="form-group">
                                <label class="col-sm-1 control-label no-padding-right" for="code"> 统计代码 </label>
                                <div class="col-sm-9">
                                    <textarea name="code" id="code" cols="45" rows="5">{$list.code}</textarea>
                                </div>
                            </div>
                            <div class="col-md-offset-2 col-md-9">
                                <input type="hidden" name="logo" id="imgurl" value="{$list.logo}">
                                <input type="hidden" name="id" id="ids" value="{$list.id}">
                                <button class="btn btn-info submit" type="button" onclick="save();">
                                    <i class="icon-ok bigger-110"></i>
                                    提交
                                </button>
                            </div>

                        </div>
                        <!-- PAGE CONTENT ENDS -->
                    </div><!-- /.col -->
                </div><!-- /.row -->
            </div><!-- /.page-content -->
        </div>
    </div><!-- /.main-content -->
    <include file="Public/footer" />
    <script src="//cdn.bootcss.com/jquery.form/3.51/jquery.form.min.js" type="text/javascript"></script>

</div><!-- /.main-container -->

<include file="Public/footerjs" />
<!-- inline scripts related to this page -->
<script type="text/javascript">
    $(document).ready(function(){
        $('#logo').change(function(){
            preSubmit();
        });

    });

    function preSubmit(){
        $("#form1").ajaxSubmit({
            success: function(data) {
                //回调
                if(data != 0){
                    $('#pic').attr('src',"__ROOT__/"+data);
                    $('#imgurl').val(data);
                }else{
                    alert('上传失败');
                }
            },
            error:function(data){
                alert('上传失败2，请重新选择图片');
            }
        })
    }
    function save(){
        var title = $("#title").val();
        var logo = $("#imgurl").val();
        var keywords = $('#keywords').val();
        var contents = $('#contents').val();
        var copyright = $('#copyright').val();
        var record = $('#record').val();
        var code = $('#code').val();
        var id = $('#ids').val();
        var urls = "{:U('Platform/index')}";
        if(title==''){
            bootbox.dialog({
                title: '友情提示：',
                message: "网站标题必须填写",
                buttons: {
                    "success" : {
                        "label" : "确定",
                        "className" : "btn-danger"
                    }
                }
            });
            return;
        }
        if(keywords== ''){
            bootbox.dialog({
                title: '友情提示：',
                message: "网站关键字必须填写。",
                buttons: {
                    "success" : {
                        "label" : "确定",
                        "className" : "btn-danger"
                    }
                }
            });
            return;
        }

        $.ajax({
            type: "post",
            url: "{:U('Platform/edit')}",
            data: "id="+id+"&title="+title+"&logo="+logo+"&keywords="+keywords+'&contents='+contents+'&copyright='+copyright+'&record='+record+'&code='+code,
            success: function(data){
                if(data == 1){
                    alert('修改成功');
                    window.location.href=urls;
                }else{
                    alert('修改失败！');
                }
            }
        });
    }
</script>
</body>
</html>
